/**
 * Created by Coing on 2017/2/26.
 */

public class Solution2 {
    public boolean isPalindrome(String s) {
        s = s.toLowerCase(); // convert all to lower cases.
        s = s.replaceAll("[^a-z^0-9]+", ""); // remove all non-digital and non-letter.
        //s = s.replaceAll("[\W]+", ""); // remove all non-digital and non-letter.
        int len = s.length();
        for (int i = 0; i < len; i++){
            if (s.charAt(i) != s.charAt(len - i - 1)){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Solution2 solution = new Solution2();
        System.out.println(solution.isPalindrome("A man, a plan, a canal: Panama"));
        System.out.println(solution.isPalindrome("ab"));

    }
}

